# Maintainer: David Runge <dvzrv@archlinux.org>

_name=johnnycanencrypt
pkgname=python-johnnycanencrypt
pkgver=0.14.1
pkgrel=1
pkgdesc="Python module for OpenPGP written in Rust"
arch=(loong64 x86_64)
url="https://github.com/kushaldas/johnnycanencrypt"
license=(LGPL-3.0-or-later)
depends=(
  bzip2
  gcc-libs
  glibc
  gmp
  nettle
  pcsclite
  python
  python-httpx
)
makedepends=(
  clang
  python-build
  python-installer
  python-setuptools
  python-setuptools-rust
  python-wheel
  rust
)
checkdepends=(
  python-pytest
  python-vcrpy
)
source=($url/releases/download/v$pkgver/$_name-$pkgver.tar.gz{,.asc})
sha512sums=('c10eaaecce8f4e2f34e2b6c0223dfbcd6c93be18a5c68fb18908ab51d9ce6fd2aaaf67fb213837bbe02eed7a9c1ec46b3593777ce4ac436bd5dae553377dce33'
            'SKIP')
b2sums=('e670955748aef70fca6c89467ac0b38117d930a74c25307300c9da747f3140515e9e19b726f479b1a7aa4a03a80fda9c26106f4f7be9351383e4c68bbe6f2770'
        'SKIP')
validpgpkeys=(A85FF376759C994A8A1168D8D8219C8C43F6C5E1)  # Kushal Das <kushal@freedom.press>

build() {
  cd $_name-$pkgver
  python -m build --wheel --no-isolation
}

check() {
  local pytest_options=(
    -vv
  )
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")

  cd $_name-$pkgver
  # install to temporary location and copy tests in place because test imports are relative :(
  python -m installer --destdir=test_dir dist/*.whl
  cp -av -- tests "test_dir/$site_packages/"
  export PYTHONPATH="$PWD/test_dir/$site_packages"
  pytest "${pytest_options[@]}" test_dir/$site_packages/tests/
}

package() {
  cd $_name-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl
}
